package cn.swpu.blog.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author 冰翔
 * @Date Created in 8:37 下午 2020/12/10
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfig {

    /**
     * 创建API应用
     * @return
     */
    @Bean
    public Docket createRestApi(){
        //Swagger2
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.swpu.blog.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * api的基本信息
     * @return
     */
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("冰翔博客的API")
                .description("这个是世界上最好的Api,没人比我更懂Api")
                .termsOfServiceUrl("www.bilibili.com")
                .version("v1.0")
                .build();
    }
}
